package com.fzkj.search.tree;

/**
 * 二叉树
 * @author yaya
 */
public class BinarySearchTree {
    public static void main(String[] args) {
        TreeNode root = TreeNode.build();
        TreeNode treeNode = binaryTreeSearch2(root, 110);
        System.out.println(treeNode.value);
    }

    private static TreeNode binaryTreeSearch(TreeNode root, int des){
        if (root == null || root.value == des){
            return root;
        }
        if (root.value > des){ // 搜索左子树
            return binaryTreeSearch(root.left, des);
        }else {
            return binaryTreeSearch(root.right, des);
        }
    }

    private static TreeNode binaryTreeSearch2(TreeNode root, int des){
        while (root != null && root.value != des){
            root = des < root.value ? root.left : root.right;
        }
        return root;
    }
}
